from db.aiomysql_connector import AioMysqlClient
from header.pm_header import PMHeader
from services.cache_service import CacheUtils
from services.sql_service.mes_service import MesService
from services.sql_service.production_service import ProductionService


class PMService:

    def __init__(self):
        self.sql_client: AioMysqlClient = CacheUtils.get('aiomysql_pool')
        self.mes_service: MesService = MesService()
        self.production_service: ProductionService = ProductionService()

    async def get_data(self):
        bom_data: dict = await self.mes_service.get_issue_order()
        pass_rate: dict = await self.production_service.get_pass_rate()
        cur_day_issued_data: dict = await self.mes_service.cur_day_issued_data()
        ten_day_data: dict = await self.mes_service.get_ten_day_data()
        data = {
            'bom': bom_data,
            'cur_day_issued_data': cur_day_issued_data,
            'ten_day_data': ten_day_data,
            'pass_rate': pass_rate
        }

        return data
